package com.it2297.view;

import javax.swing.JPanel;
import javax.swing.BoxLayout;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import java.awt.Dimension;
import javax.swing.JToolBar;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.CardLayout;
import javax.swing.JRadioButton;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.ImageIcon;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JLabel;
import java.awt.ComponentOrientation;

@SuppressWarnings("serial")
public class DonationReportView extends JPanel
{
	private final JPanel panel = new JPanel();
	private final JPanel panel_1 = new JPanel();
	private final JPanel panel_2 = new JPanel();
	private final JScrollPane scrollPane = new JScrollPane();
	private final JTable table = new JTable();
	private final JScrollPane scrollPane_1 = new JScrollPane();
	private final JTable table_1 = new JTable();
	private final JToolBar toolBar = new JToolBar();
	private final JRadioButton rdbtnDaily = new JRadioButton("Today only");
	private final JRadioButton rdbtnWeekly = new JRadioButton("Last 7 days");
	private final JRadioButton rdbtnMonthly = new JRadioButton("Last 30 days");
	private final Component horizontalStrut = Box.createHorizontalStrut(20);
	private final Component horizontalStrut_1 = Box.createHorizontalStrut(20);
	private final JButton btnRefresh = new JButton("Refresh");
	private final Component horizontalStrut_2 = Box.createHorizontalStrut(20);
	private final JScrollPane scrollPane_2 = new JScrollPane();
	private final JTable table_2 = new JTable();
	private final JScrollPane scrollPane_3 = new JScrollPane();
	private final JTable table_3 = new JTable();
	private final JPanel panel_3 = new JPanel();
	private final JPanel panel_4 = new JPanel();
	private final JLabel lblTotalItemDonated = new JLabel("Total Item Donated:");
	private final JLabel lblTotalBids = new JLabel("Total Bids:");
	private final JLabel lblTotalUniqueDonor = new JLabel("Total Unique Donor:");
	private final JLabel lblTotalUniqueBidder = new JLabel("Total Unique Bidder:");
	private final JLabel lblApprovedRequest = new JLabel("Approved Request:");
	private final JLabel lblPendingRequest = new JLabel("Pending Request:");
	private final JLabel lblRejectedRequest = new JLabel("Rejected Request:");
	private final JLabel lblEndedRequest = new JLabel("Ended Request:");
	private final JLabel _lblTotalItemDonated = new JLabel("");
	private final JLabel _lblTotalBids = new JLabel("");
	private final JLabel _lblTotalUniqueDonor = new JLabel("");
	private final JLabel _lblTotalUniqueBidder = new JLabel("");
	private final JLabel _lblApprovedRequest = new JLabel("");
	private final JLabel _lblPendingRequest = new JLabel("");
	private final JLabel _lblRejectedRequest = new JLabel("");
	private final JLabel _lblEndedRequest = new JLabel("");
	private final Component horizontalStrut_3 = Box.createHorizontalStrut(20);
	private final JRadioButton rdbtnOverall = new JRadioButton("Overall Report");
	private final ChartPanel chartPanel = new ChartPanel(null);
	private final DefaultTableModel topBidderTableModel = new DefaultTableModel();
	private final DefaultTableModel topDonorTableModel = new DefaultTableModel();
	private final DefaultTableModel mostPopularBidTableModel = new DefaultTableModel();
	private final DefaultTableModel recentWonBidTableModel = new DefaultTableModel();

	/**
	 * Create the panel.
	 */
	public DonationReportView()
	{
		initGUI();
	}

	private void initGUI()
	{
		this.setBounds(100, 100, 750, 570);
		this.setLayout(new BorderLayout(0, 0));
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		panel_2.setLayout(new CardLayout(0, 0));

		add(panel_2);
		toolBar.setFloatable(false);

		panel_2.add(toolBar, "name_17801409769376");
		btnRefresh.setIcon(new ImageIcon(DonationReportView.class.getResource("/com/alee/extended/filechooser/icons/refresh.png")));

		toolBar.add(btnRefresh);

		toolBar.add(horizontalStrut_2);

		toolBar.add(rdbtnDaily);

		toolBar.add(horizontalStrut);

		toolBar.add(rdbtnWeekly);

		toolBar.add(horizontalStrut_1);

		toolBar.add(rdbtnMonthly);

		toolBar.add(horizontalStrut_3);

		toolBar.add(rdbtnOverall);
		panel.setPreferredSize(new Dimension(10, 500));
		panel_1.setPreferredSize(new Dimension(10, 200));
		scrollPane.setFocusable(false);
		scrollPane.setMaximumSize(new Dimension(32767, 200));

		panel_1.add(scrollPane);
		table.setFocusable(false);
		table.setFillsViewportHeight(true);
		table.setModel(topBidderTableModel);

		scrollPane.setViewportView(table);

		scrollPane_1.setFocusable(false);
		scrollPane_1.setMaximumSize(new Dimension(32767, 200));

		panel_1.add(scrollPane_1);
		table_1.setFocusable(false);
		table_1.setModel(topDonorTableModel);
		table_1.setFillsViewportHeight(true);

		scrollPane_1.setViewportView(table_1);

		add(panel_4, BorderLayout.NORTH);
		panel_4.setLayout(new BoxLayout(panel_4, BoxLayout.X_AXIS));
		panel_4.add(panel_3);
		panel_3.setLayout(new FormLayout(new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, }));

		panel_3.add(lblTotalItemDonated, "2, 2");

		panel_3.add(_lblTotalItemDonated, "4, 2");

		panel_3.add(lblTotalBids, "2, 4");

		panel_3.add(_lblTotalBids, "4, 4");

		panel_3.add(lblTotalUniqueDonor, "2, 6");

		panel_3.add(_lblTotalUniqueDonor, "4, 6");

		panel_3.add(lblTotalUniqueBidder, "2, 8");

		panel_3.add(_lblTotalUniqueBidder, "4, 8");

		panel_3.add(lblApprovedRequest, "2, 10");

		panel_3.add(_lblApprovedRequest, "4, 10");

		panel_3.add(lblPendingRequest, "2, 12");

		panel_3.add(_lblPendingRequest, "4, 12");

		panel_3.add(lblRejectedRequest, "2, 14");

		panel_3.add(_lblRejectedRequest, "4, 14");

		panel_3.add(lblEndedRequest, "2, 16");

		panel_3.add(_lblEndedRequest, "4, 16");

		chartPanel.setPreferredSize(new Dimension(450, 200));
		panel_4.add(chartPanel);

		add(panel_1, BorderLayout.NORTH);
		panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS));
		add(panel, BorderLayout.NORTH);
		panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

		panel.add(scrollPane_2);
		table_2.setFocusable(false);
		table_2.setModel(mostPopularBidTableModel);

		scrollPane_2.setViewportView(table_2);

		panel.add(scrollPane_3);
		table_3.setFocusable(false);
		table_3.setModel(recentWonBidTableModel);

		scrollPane_3.setViewportView(table_3);
	}

	public void setTotalItemDonated(int totalItemDonated)
	{
		_lblTotalItemDonated.setText(Integer.toString(totalItemDonated));
	}

	public void setTotalBids(int totalBids)
	{
		_lblTotalBids.setText(Integer.toString(totalBids));
	}

	public void setTotalUniqueDonor(int totalUniqueDonor)
	{
		_lblTotalUniqueDonor.setText(Integer.toString(totalUniqueDonor));
	}

	public void setTotalUniqueBidder(int totalUniqueBidder)
	{
		_lblTotalUniqueBidder.setText(Integer.toString(totalUniqueBidder));
	}

	public void setTotalApproved(int totalApproved)
	{
		_lblApprovedRequest.setText(Integer.toString(totalApproved));
	}

	public void setTotalPending(int totalPending)
	{
		_lblPendingRequest.setText(Integer.toString(totalPending));
	}

	public void setTotalRejected(int totalRejected)
	{
		_lblRejectedRequest.setText(Integer.toString(totalRejected));
	}

	public void setTotalEnded(int totalEnded)
	{
		_lblEndedRequest.setText(Integer.toString(totalEnded));
	}

	public void setChart(JFreeChart chart)
	{
		chartPanel.setChart(chart);
	}

	public void setTopBidder(Object[][] data)
	{
		topBidderTableModel.setDataVector(data, new String[] { "", "Top Bidders", "" });
	}

	public void setTopDonor(Object[][] data)
	{
		topDonorTableModel.setDataVector(data, new String[] { "", "Top Donors", "" });
	}

	public void setMostPopularBid(Object[][] data)
	{
		mostPopularBidTableModel.setDataVector(data, new String[] { "", "Popular Bids", "" });
	}

	public void setRecentWonBid(Object[][] data)
	{
		recentWonBidTableModel.setDataVector(data, new String[] { "", "Recent Won Bid", "" });
	}

}
